﻿#region

using System;
using System.Collections.Generic;
using Lab.Common.Dto;
using Lab.Server.Domain;

#endregion

namespace Lab.Test.Test.Common {
    public class Create {
        private static int incrementCounter = 1;

        private static int UniqueInt {
            get { return incrementCounter++; }
        }

        public static DtoVacancy DtoVacancy(string name = "",
                                            DateTime? openVacancy = null,
                                            string location = "",
                                            int expectedLevelOfSalary = 0,
                                            List<DtoSkill> skills = null,
                                            DtoKindOfActivity kindOfActivity = null,
                                            DtoEmployer employer = null, int? id = null, bool? isOpen = null) {
            id = id ?? UniqueInt;
            isOpen = isOpen ?? true;
            openVacancy = openVacancy ?? DateTime.UtcNow;
            skills = skills ?? new List<DtoSkill>();
            kindOfActivity = kindOfActivity ?? DtoKindOfActivity();
            employer = employer ?? DtoEmployer();
            return new DtoVacancy {
                                      Id = id.Value,
                                      Name = name,
                                      OpenVacancy = openVacancy.Value,
                                      Location = location,
                                      ExpectedLevelOfSalary = expectedLevelOfSalary,
                                      Skills = skills,
                                      KindOfActivity = kindOfActivity,
                                      Employer = employer,
                                      IsOpen = isOpen.Value
                                  };
        }

        public static DtoEmployer DtoEmployer(string name = "employer name",
                                              string address = null,
                                              string telephoneNumber = null,
                                              List<DtoKindOfActivity> kindOfActivity = null) {
            kindOfActivity = kindOfActivity ?? new List<DtoKindOfActivity> { DtoKindOfActivity() };
            return new DtoEmployer {
                                       Name = name,
                                       Address = address,
                                       TelephoneNumber = telephoneNumber,
                                       KindOfActivities = kindOfActivity
                                   };
        }

        public static Employer Employer(string name = "employer", List<KindOfActivity> kindOfActivity = null) {
            kindOfActivity = kindOfActivity ?? new List<KindOfActivity>();
            return new Employer { Name = name, KindOfActivities = kindOfActivity };
        }

        public static DtoKindOfActivity DtoKindOfActivity(int? id = null, string description = "description") {
            id = id ?? UniqueInt;
            return new DtoKindOfActivity { Id = id.Value, Description = description };
        }

        public static KindOfActivity KindOfActivity(int? id = null, string description = "description") {
            id = id ?? UniqueInt;
            return new KindOfActivity { Id = id.Value, Description = description };
        }

        public static DtoSkill DtoSkill(string description = "Default skill", int? id = null) {
            id = id ?? UniqueInt;
            return new DtoSkill { Id = id.Value, Description = description };
        }

        public static DtoApplicant DtoApplicant(string surname = null, string name = null, string middleName = null,
                                                DtoKindOfActivity kindOfActivity = null, string placeOfResidence = null,
                                                List<DtoSkill> skills = null, int? id = null) {
            id = id ?? UniqueInt;
            kindOfActivity = kindOfActivity ?? DtoKindOfActivity();
            skills = skills ?? new List<DtoSkill> { DtoSkill() };
            return new DtoApplicant {
                                        Id = id.Value,
                                        Surname = surname,
                                        Name = name,
                                        MiddleName = middleName,
                                        KindOfActivity = kindOfActivity,
                                        PlaceOfResidence = placeOfResidence,
                                        Skills = skills
                                    };
        }

        public static DtoDeal DtoDeal(DtoApplicant applicant = null, DtoEmployer employer = null,
                                      DtoVacancy vacancy = null) {
            applicant = applicant ?? DtoApplicant();
            employer = employer ?? DtoEmployer();
            vacancy = vacancy ?? DtoVacancy();
            return new DtoDeal { Applicant = applicant, Employer = employer, Vacancy = vacancy };
        }
    }
}